<?php
class MLAdmin extends MModule {
    protected static $_version = '0.01';

    public static function initUser(){
        $loginRoute = __route('ml-admin/login');
        if (!MSession::getInstance()->isLogged() && !MRequest::isCurrentUrl($loginRoute)){
            __redirect($loginRoute);
        }
    }

    public static function initModel(){
        ActiveRecord\Config::initialize(function($cfg){
            $cfg->set_model_directory(__DIR__.DS.'models');
            $cfg->set_connections(Mandrill::getApp()->dbConnection);
            $cfg->set_default_connection('mandrill');
        });
    }

    public static function initJavascript(){
        MPackage::import('jquery');
        MPackage::import('jquery-editor');
    }
   
    public static function initMenu(){
        $installedModules = Module::all();
        MTemplate::getInstance()->addVar('installedModules', $installedModules);
    }

    public static $classes = array(
        'HomeController'=>'/controllers/home.php',
        'LoginController'=>'/controllers/login.php',
        'ModuleController'=>'/controllers/module.php',
        'SettingController'=>'/controllers/setting.php',
        'PageController'=>'/controllers/page.php',
        'LoginForm'=>'/forms/loginForm.php',
        'ModuleInstallForm'=>'/forms/moduleInstallForm.php',
        'SettingsForm'=>'/forms/settingsForm.php',
        'CreatePageForm'=>'/forms/createPageForm.php',
    );
}
?>
